﻿using Microsoft.Xaml.Behaviors;
using System.Windows.Controls;

namespace Common
{
    public class MouseWheelBehavior : Behavior<TextBox>
    {
        protected override void OnAttached()
        {
            base.OnAttached();
            AssociatedObject.MouseWheel += AssociatedObject_MouseWheel;
        }

        private void AssociatedObject_MouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e)
        {
            var value = int.Parse(AssociatedObject.Text);
            if (e.Delta > 0)
            {
                value += 1;
            }
            else
            { 
                value -= 1;
            }
            AssociatedObject.Text = value.ToString();
        }
    }
}
